/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package stis.statpro.ibs.widget;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

/**
 *
 * @author habib <imamhabibpamungkas@gmail.com>
 */
public class EfekKaca {
    public static BufferedImage getBufferedImage(Image source) {
        int width = source.getWidth(null);
        int height = source.getHeight(null);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gd = (Graphics2D) image.getGraphics();
        gd.drawImage(source, 0, 0, null);
        gd.dispose();
        
        return image;
    }
    
    public static BufferedImage getEfekKaca(BufferedImage source){
        BufferedImage image = new BufferedImage(source.getWidth(), source.getHeight()+source.getHeight()/2+10, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gd = (Graphics2D) image.getGraphics();
        gd.drawImage(source, 0, 0,null);
        gd.scale(1, -1);
        gd.drawImage(source, 0, -source.getHeight()*2, null);
        gd.scale(1, -1);
        gd.translate(0, source.getHeight());
        gd.setPaint(new GradientPaint(0, 0, new Color(1f, 1f, 1f, 0.3f), 0, source.getHeight()/2+10, new Color(1f, 1f, 1f, 0f)));
        gd.setComposite(AlphaComposite.DstIn);
        gd.fillRect(0, 0, source.getWidth(), source.getHeight());
        gd.dispose();
        
        return image;
    }
    
    public static BufferedImage getEfekKaca(Image source){
        return EfekKaca.getEfekKaca(EfekKaca.getBufferedImage(source));    
    }
}
